/**
 * 
 */
package com.ambow.servlet;

import java.io.IOException;


import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ambow.Entity.TextBook;
import com.ambow.service.TextBookService;
import com.ambow.service.impl.TextBookServiceImpl;

/**
 * @author Administrator
 *
 */
public class TextBookServlet extends HttpServlet {
	 TextBookService  textBookService=new TextBookServiceImpl();

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	String status = request.getParameter("status");
	if(status.equals("query")) {
		query(request,response);
	}else if(status.equals("queryOne")) {
		queryOne(request,response);
	}
    	
}
private void queryOne(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	Integer id=Integer.valueOf(request.getParameter("id"));
    System.out.println("11wwwww"+id);
	TextBook textBook=textBookService.queryOne(TextBook.class, id);
	request.setAttribute("textbook", textBook);
	System.out.println("textbook>>>>>"+textBook);

request.getRequestDispatcher("pages/module/storage/storage003/book_detail.jsp").forward(request, response);
	
	
}
//
private void query(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	String isbn = request.getParameter("isbn");//所查询书籍的isbn
	String hql = "from TextBook where isbn=?";
	String[] param = {isbn};
	TextBook textBook = textBookService.queryByHql(hql,param);
	if(textBook!=null) {
		System.out.println("查询成功");
		request.setAttribute("tBook", textBook);
		request.getRequestDispatcher("pages/module/storage/storage002/get_receivebook.jsp").forward(request, response);
	}
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	// TODO Auto-generated method stub
   this.doPost(request, response);
}

  
}
